package com.txhy.certificatechain.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.txhy.certificatechain.R;
import com.txhy.certificatechain.model.bean.UserBean;
import com.txhy.certificatechain.utils.UIUtils;

import java.util.List;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: DialogNameAdapter.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 对话框适配器
 * 创建时间: 2018/9/20 8:34
 * 更新时间：2018/9/20 8:34
 * -----------------------------------------------------------------
 * 2018/9/20 8:34: 创建 DialogNameAdapter.java (侯建军);
 * -----------------------------------------------------------------
 */
public class DialogNameAdapter  extends BaseAdapter {
    private List<UserBean.DataEntity.MapEntity> list;
    private Context context;

    public DialogNameAdapter(List<UserBean.DataEntity.MapEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView==null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_dialog_name,null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            holder.im_check = (ImageView) convertView.findViewById(R.id.im_check);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_name.setText(list.get(position).getEnterpriseName());
        if(TextUtils.isEmpty(list.get(position).getRoleName())){
            holder.tv_type.setText("个人");
        }else{
            holder.tv_type.setText(list.get(position).getRoleName());
        }

        if(list.get(position).isCheck()){
            holder.im_check.setVisibility(View.VISIBLE);
            holder.tv_name.setTextColor(UIUtils.getColor(R.color.ed584c));
        }else{
            holder.im_check.setVisibility(View.GONE);
            holder.tv_name.setTextColor(UIUtils.getColor(R.color.text423b));
        }
        return convertView;
    }

    static class ViewHolder{
        TextView tv_name,tv_type;
        ImageView im_check;
    }
    public void cotifyAdapter(List<UserBean.DataEntity.MapEntity> list){
        this.list=list;
        notifyDataSetChanged();
    }
}

